package corej.course.collection.set.hashset;

public class Employee {
    private String name;

    private int age;

    private double salary;

    /**
     * @param name
     * @param age
     * @param salary
     */
    public Employee(String name, int age, double salary) {
        super();
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    /*
      * (non-Javadoc)
      *
      * @see java.lang.Object#hashCode()
      */
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + age;
        result = PRIME * result + ((name == null) ? 0 : name.hashCode());
        long temp;
        temp = Double.doubleToLongBits(salary);
        result = PRIME * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    /*
      * (non-Javadoc)
      *
      * @see java.lang.Object#equals(java.lang.Object)
      */
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Employee other = (Employee) obj;
        if (age != other.age)
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (Double.doubleToLongBits(salary) != Double
                .doubleToLongBits(other.salary))
            return false;
        return true;
    }

    public String toString() {
        return "Employee name: " + name + ", age: " + age + ", salary: "
                + salary;
    }

    /*
      * public boolean equals (Object obj) { System.out.println("run
      * equals()...."); if(this==obj) return true; if(o==null) return false;
      * if(this.getClass()!= o.getClass()) return false; Employee e =
      * (Employee)obj;
      * if(this.name.equals(e.name)&&this.age==obj.age&&this.salary==obj.salary)
      * return ture; else return false; }
      *
      * public int hashCode() { return this.age+this.name.hashCode()+(new
      * Double(salary)).hashCode() ; }
      */
}
